package com.shuang.graph11;

import java.util.*;
 //并查集解决无向图中 判断两个元素是否在一个集合里
public class Main{
    public static void main(String[] args) {
        int N, M;
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        M = scanner.nextInt();
        DisJoint disJoint = new DisJoint(N + 1);
        for (int i = 0; i < M; ++i) {
            disJoint.join(scanner.nextInt(), scanner.nextInt());
        }
        if(disJoint.isSame(scanner.nextInt(), scanner.nextInt())) {
            System.out.println("1");
        } else {
            System.out.println("0");
        }
    }
  
}
 
//并查集模板 
class DisJoint{
    private int[] father;
 
    //先将所有节点都指向自己
    public DisJoint(int N) {
        father = new int[N];
        for (int i = 0; i < N; ++i){
            father[i] = i;
        }
    }
 
    //寻找节点的根
    public int find(int n) {
 
        //如果该节点等于自己了就找到根了       
        if (n == father[n]){
            return n;
        }
        //优化处理将该节点直接连到根上
        father[n] = find(father[n]);
 
        return father[n];
    }
 
    //将两个节点加到一个集合中
    public void join (int n, int m) {
        n = find(n);
        m = find(m);
        if (n == m) return;
        father[m] = n;
    }
 
    //判断两个节点是否在一个集合里
    public boolean isSame(int n, int m){
        n = find(n);
        m = find(m);
        return n == m;
    }
  
}